package org.example.acl;

import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class UserRepository {

    public static final List<User> USERS = List.of(
            new User(1, "bob"),
            new User(2, "john")
    );

    public User getById(Integer id) {
        return USERS.stream()
                .filter(user -> user.getId().equals(id))
                .findFirst()
                .orElse(null);
    }

    public User getByName(String name) {
        return USERS.stream()
                .filter(user -> user.getName().equals(name))
                .findFirst()
                .orElse(null);
    }

    public List<User> all() {
        return new ArrayList<>(USERS);
    }
}
